package cn.sjx.graduate.service.impl;

import cn.sjx.graduate.domain.Department;
import cn.sjx.graduate.mapper.DepartmentMapper;
import cn.sjx.graduate.qo.QueryObject;
import cn.sjx.graduate.service.IDepartmentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bo-feifei
 * @since 2021-11-07
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Department> departments = departmentMapper.selectList(null);
        return new PageInfo<>(departments);
    }

    @Override
    public IPage<Department> queryPage(QueryObject qo) {
        IPage<Department> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());
        QueryWrapper<Department> wrapper = Wrappers.query();
        IPage<Department> page1 = super.page(page, wrapper);
        List<Department> records = page1.getRecords();
        int size = records.size();
        String s = String.valueOf(size);
        page1.setTotal(Long.parseLong(s));
        return page1;
    }
}
